/*
package com.idlecode.util;

import com.idlecode.panel.DataSourcesPanel;

import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumn;

*/
/**
 * @program: IdleCode
 * @description
 * @author: rongjuwei
 * @create: 2024-02-06 18:02
 **//*

public class TableUtil {

    public static void setColumnProportionalWidth(JTable table, int columnIndex, double proportion, int jpWidth) {
        TableColumn column = table.getColumnModel().getColumn(columnIndex);
        int width = (int) (proportion * jpWidth);
        column.setPreferredWidth(width);
    }

    public static void setHeaderAlignment(JTableHeader header, int alignment) {
        for (int i = 0; i < header.getColumnModel().getColumnCount(); i++) {
            TableColumn column = header.getColumnModel().getColumn(i);
            column.setHeaderRenderer(new DataSourcesPanel.HeaderRenderer(alignment));
        }
    }

    public static class HeaderRenderer extends DefaultTableCellRenderer {
        HeaderRenderer(int alignment) {
            setHorizontalAlignment(alignment);
        }
    }

    // 清除表格模型中的数据
    public static void clearData(DefaultTableModel model) {
        int rowCount = model.getRowCount();
        for (int i = rowCount - 1; i >= 0; i--) {
            model.removeRow(i);
        }
    }
}
*/
